package com.wyix.create;

/**
 * 动物赛跑模拟
 *
 * @author wangdx
 * @since 2025/8/4
 */
public class AnimalRace extends Thread {
    private String animalName;
    private int speed;

    public AnimalRace(String animalName, int speed) {
        this.animalName = animalName;
        this.speed = speed;
    }

    @Override
    public void run() {
        System.out.println(animalName + " 开始比赛");
        for (int i = 1; i <= 100; i += speed) {
            System.out.println(animalName + " 跑了 " + i + " 米");
            try {
                // 模拟不同动物的奔跑间歇
                Thread.sleep(300);
            } catch (InterruptedException e) {
                System.out.println(animalName + " 被打断了!");
                return;
            }
        }
        System.out.println("🎉 " + animalName + " 到达终点!");
    }

    public static void main(String[] args) {
        System.out.println("🏁 动物赛跑开始!");
        new AnimalRace("兔子", 10).start();
        new AnimalRace("乌龟", 2).start();
        new AnimalRace("小狗", 5).start();
    }
}
